const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag:true,
    currentTabsIndex:0,
    index: 0,
    index1:0,
    index2: 0,
    danwei: ['请选择招聘单位'],
    gangwei: ['请选择招聘岗位'],
    leibie:['请选择笔试类别'],
    xingbie: 0,
    xingming: '',
    fenshu: '',
    page: 32,

    phone: 0,
    theList: '',
    theGw: '',
    myph: 0,
    zrs: 0
  },
// 遮罩层显示
show: function () {
  this.setData({ flag: false })
},
// 遮罩层隐藏
quxiao: function () {
  this.setData({ flag: true })
},



  onTabsItemTap:function(e){
    var that=this
    console.log(e.currentTarget.dataset.index)
    that.setData({
      currentTabsIndex:e.currentTarget.dataset.index
    })
  },
  nameInput: function (e) {
    this.setData({
      xingming: e.detail.value
    })
    console.log(this.data.xingming)
  },
  fenshuInput: function (e) {
    this.setData({
      fenshu: e.detail.value
    })
    console.log(this.data.fenshu)
  },

  bindPickerChange: function (e) {
    let num = e.detail.value;
    let that = this;
    console.log('danwei发送选择改变，携带值为', that.data.danwei[num]);
    this.setData({
      index: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/shaifen/getlevel?actid=45075&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'danwei',
        grtext: that.data.danwei[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson.lists)
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].gangwei)
        }
        that.setData({
          gangwei: list
        });
      }
    })
  },
  bindPickerChange1: function (e) {
    var that=this
    let num1 = e.detail.value;
    console.log('gangwei发送选择改变，携带值为', that.data.gangwei[num1]);
    this.setData({
      index1: e.detail.value
    })
    console.log(that.data.index1)
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/shaifen/getlevel?actid=45075&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'gangwei',
        grtext: that.data.gangwei[num1],
        onefiled: 'danwei',
        onetext: that.data.danwei[that.data.index]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson.lists)
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].leibie)
        }
        that.setData({
          leibie: list
        });
      }
    })
  },
  bindPickerChange2: function (e) {
    let num2 = e.detail.value;
    let that = this;
    console.log('leibie发送选择改变，携带值为', that.data.leibie[num2]);
    this.setData({
      index2: e.detail.value
    })

  },



  onLoad: function (options) {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/shaifen/getlevel?actid=45075&callback=?', //接收url
      data: {
        level: '1',
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择招聘单位')
        console.log(theJson.lists);
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].danwei)
        }
        that.setData({
          danwei: list
        });
      }
    })

    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
// 晒分
    wx.showLoading({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    });
    var phone = wx.getStorageSync('phone');
    var gangwei = that.data.gangwei[that.data.index1];
    this.setData({
      phone: phone
    })
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/shaifen/getphonestatus/?actid=45075&callback=?",
      data: {
        phone: phone,
        gangwei:gangwei

      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.status)
        if (theJson.status == '1') {
          let phone = theJson.user.phone;
          wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/shaifen/getphoneinfo/?actid=45075&callback=?",
            data: {
              phone: phone,
              limits: 100
            }, //接收参数
            success(res) { //返回
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              };
              console.log(theJson)
              that.setData({
                theList: theJson.lists,
                zrs: theJson.zcounts,
                myph: theJson.users.dqpaiming,
              })
              console.log(that.data.theList)
            }
          })
        } 


      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },



  tijiao() {
    var that = this;
    var danwei = that.data.danwei[that.data.index];
    var gangwei = that.data.gangwei[that.data.index1];
    var leibie = that.data.leibie[that.data.index2];
    var fenshu = that.data.fenshu;
    var name = that.data.xingming;
    let phone = wx.getStorageSync('phone')
    if (fenshu== '' || fenshu == undefined) {
      wx.showToast({
        title: '请输入您的分数',
        icon: 'none',
        duration: 1000,
        mask: true
      })

      return false
    }
    if (name== '' || name == undefined) {
      wx.showToast({
        title: '请输入您的姓名',
        icon: 'none',
        duration: 1000,
        mask: true
      })

      return false
    }
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/shaifen/register?actid=45075&callback=?', //接收url
        data: {
          danwei: danwei,
          gangwei: gangwei,
          leibie: leibie,
          fenshu: fenshu,
          name:name,
          phone: phone,
          fenxiao: that.data.area,
          geneal: that.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
         that.setData({ flag: false })
        }
      })
  
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShdanweippMessage: function () {

  }
})